package com.lagouedu.cfgcenter.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

@Configuration
public class DruidConfig {

    @Qualifier("dataResourceConfig")
    @Autowired
    DatabaseConfig databaseConfig;

    @Bean("druidDataSrouce")
    @DependsOn("dataResourceConfig")
    public DruidDataSource getDataSource() throws Exception {

        DruidDataSource dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(databaseConfig.toMap());
        return dataSource;
    }
}
